Plot two distributions on one figure:


    • [bars1,height1]=hist(A,[minvalue:step:maxvalue]);
    • [bars2,height2]=hist(B,[minvalue:step:maxvalue]);
    • figure,bar(height1,bars1);
    • hold on
    • bar(height2,bars2);
    • hold off


Comparison

intersect comparison of 2 arrays
corrcoef calcualtion of correlation coefficient
strcmp comparison of 2 strings



Arrays



Assume you have an array tmp:
    • tmp = [1 2 3 4 5];

You want to set all elements of the array to be zero if they are bigger than 2 and smaller than 5:
    • tmp(tmp>2 & tmp <5)=0

Invert the problem: set to zero all other elements:
    • tmp(tmp<2 | tmp >5)=0

Get diagonal elements of a matrix:
    • diag(m)


Read data files

function S=ReadAllDat(PATH,add)
% the function from the PATH reads all the files with the .dat and stores
% them into the structure S, so that there are the field in the S structure
% named as the dat files and containing the data of the dat files
% Read more about structures in MAtlab documentations
%
% !!! IMPORTANT: all the files names (in the PATH folder) should have only one "." sighn in their
% names
% !!! data files should contain only numeric data.
%
% INPUT:
% PATH - string with the path to the folder containing required dat files
% add - prefix to the structure fileds, usually just empty string.
% OUTPUT:
% S - structure containing the data of the dat files

Example usage:
sys=ReadAllDat('/net/st7000/export/people/frolov/PULLIONSproject/calc_pot','');





Average structure data

function S=AverStruct(S,str0)
% the function takes the structure S, searchs for the fileds which contain
% str0 string in their name, then averages the second collumn of the
% selected fields data, stores the the data as the separate filed in the
% structure with the name "average_<str0>"
% Very useful to use together with the ReadAllDat.m script.
% If no str0 provided: then the script averages all fields.
% The suport for the averaged data is taken from the first field data. So,
% the support (first collumn) must be the same for all fields you are going
% to average.

Example usage:
sys=AverStruct(sys,'ab025sha')